package com.jzqf.harmonydemo.services;

import com.jzqf.harmonydemo.utils.LogUtil;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.rpc.IRemoteObject;

import java.util.Timer;
import java.util.TimerTask;

/**
 * service
 *
 * @author LiuWeiHao
 * 2021/5/19 16:45
 */
public class ServiceAbility extends Ability {
    private static final String TAG = ServiceAbility.class.getSimpleName();

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        LogUtil.d(TAG, "onStart");
    }

    @Override
    public void onBackground() {
        super.onBackground();
        LogUtil.d(TAG, "onBackground");
    }

    @Override
    public void onStop() {
        super.onStop();
        LogUtil.d(TAG, "onStop");
    }

    @Override
    public void onCommand(Intent intent, boolean restart, int startId) {
        LogUtil.d(TAG, "onCommand");
        task();
    }

    @Override
    public IRemoteObject onConnect(Intent intent) {
        LogUtil.d(TAG, "onConnect");
        return null;
    }

    @Override
    public void onDisconnect(Intent intent) {
        LogUtil.d(TAG, "onDisconnect");
    }

    private void task() {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                LogUtil.d(TAG, "isAlive");
            }
        }, 0L, 60000L);
    }
}